home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / OGRID100 / GLSUPPRT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-28  |  11KB  |  337 lines

  1. {********************************************************************
  2.  
  3.   OOGrid Library(TM) v1.0 for Borland/Turbo Pascal (Real Mode/TV)
  4.   Copyright (C) 1994 by Arturo J. Monge
  5.   Portions Copyright (C) 1989,1990 Borland International, Inc.
  6.  
  7.   OOGrid Library(TM) Support Unit:
  8.     This unit implements and defines several support objects,
  9.     records and constants used by the TSpreadSheet object.
  10.  
  11.   Copyright (C) 1994 by Arturo J. Monge
  12.  
  13.   Last Modification : December 29th, 1994
  14.  
  15. *********************************************************************}
  16.  
  17. {$O+,F+}
  18.  
  19. unit GLSupprt;
  20.  
  21. {****************************************************************************}
  22.                                  interface
  23. {****************************************************************************}
  24.  
  25. uses Objects, Dialogs, Drivers, Views, GLEquate;
  26.  
  27. var
  28.   GLResFile : PResourceFile;
  29.   { Pointer to the resource file to be used by the unit's objects.
  30.     Allways remember to close the resource file associated with
  31.     this pointer }
  32.  
  33.   GLStringList : PStringList;
  34.   { Pointer to the string list to be used by the unit's objects.
  35.     Allways remember to dispose the associated TStringList object }
  36.  
  37. const
  38.  
  39. { String key constants }
  40.  
  41.   sAutoCalcLetter        = 1;
  42.   sBlockDeleteMsg        = 2;
  43.   sBlockName             = 3;
  44.   sCancelPrintJob        = 4;
  45.   sCellError             = 5;
  46.   sCellLockedInfo        = 6;
  47.   sCellsProtectedMsg     = 7;
  48.   sCellUnlockedInfo      = 8;
  49.   sColumnEntryIndicator  = 9;
  50.   sCopyCellsMsg          = 10;
  51.   sDisplayFormulasLetter = 11;
  52.   sDisplayHeadersLetter  = 12;
  53.   sEmptyCellName         = 13;
  54.   sEndKeyPressedLetter   = 14;
  55.   sFilePrintErrorMsg     = 15;
  56.   sFormatErrorMsg        = 16;
  57.   sFormatError1Msg       = 17;
  58.   sFormatError2Msg       = 18;
  59.   sFormulaCellName       = 19;
  60.   sInvalidCellMsg        = 20;
  61.   sInvalidWidthMsg       = 21;
  62.   sMoveCellsMsg          = 22;
  63.   sParseError1           = 23;
  64.   sParseError2           = 24;
  65.   sParseError3           = 25;
  66.   sParseError4           = 26;
  67.   sParseError5           = 27;
  68.   sParseError6           = 28;
  69.   sParseError7           = 29;
  70.   sPrinterPrintErrorMsg  = 30;
  71.   sPrintInitErrorMsg     = 31;
  72.   sPrintToWildCard       = 32;
  73.   sRecalcMsg             = 33;
  74.   sRepeatCellName        = 34;
  75.   sTempFileName          = 35;
  76.   sTextCellName          = 36;
  77.   sValueCellName         = 37;
  78.   sWidthLetter           = 38;
  79.  
  80. const
  81.  
  82. { Additional stream status constants }
  83.  
  84.   stNoMemoryError = -7;
  85.   stInvalidFormatError = -8;
  86.  
  87. const
  88.  
  89. { Default values constants }
  90.  
  91.   DefaultCurrencyString = ' $ ';
  92.   DefaultDefaultColWidth = 10;
  93.   DefaultDefaultDecimalPlaces = 2;
  94.   DefaultEmptyRowsAtBottom = 0;
  95.   DefaultEmptyRowsAtTop = 0;
  96.   DefaultHScrollBarLimit = 27;
  97.   DefaultVScrollBarLimit = 104;
  98.   DefaultMaxDecimalPlaces = 8;
  99.   DefaultMaxCols = MaxInt;
  100.   DefaultMaxRows = MaxInt;
  101.   DefaultMinColWidth = 1;
  102.  
  103. type
  104.   CellPos = record
  105.   { Stores the position of a cell in the spreadsheet }
  106.     Col : Word;
  107.     Row : Word;
  108.   end; {...CellPos }
  109.  
  110.   PBlock = ^TBlock;
  111.   TBlock = object(TObject)
  112.   { Stores the starting and ending position of a block of cells.
  113.     It can extend the block of cells in any direction }
  114.       AnchorColShifted,
  115.       AnchorRowShifted : Boolean;
  116.       Anchor,
  117.       Start,
  118.       Stop : CellPos;
  119.     constructor Init(InitStart : CellPos);
  120.     function CellInBlock(CheckCell : CellPos) : Boolean;
  121.     function ExtendTo(NewLoc : CellPos) : Boolean; virtual;
  122.     constructor Load(var S: TStream);
  123.     procedure Store(var S: TStream);
  124.   end; {...TBlock }
  125.  
  126. var
  127.   PrinterConfigRec : record
  128.   { When printing a document, TSpreadSheet's print method will make
  129.     reference to this record. It is always initialized with the default
  130.     values }
  131.     PrinterCondensedOnCode : String;
  132.     PrinterCondensedOffCode : String;
  133.     PrinterUnderlineOnCode : String;
  134.     PrinterUnderlineOffCode : String;
  135.     PrinterBoldOnCode : String;
  136.     PrinterBoldOffCode : String;
  137.   end; {...PrinterConfigRec }
  138.  
  139. const
  140.  
  141. { Default printer setup values constants }
  142.  
  143.   DefaultPrinterName = 'PRN';
  144.   DefaultTopMargin = '0';
  145.   DefaultBottomMargin = '0';
  146.   DefaultLeftMargin = '0';
  147.   DefaultRightMargin = '0';
  148.   DefaultPageRows = '60';
  149.   DefaultNormalCols = '80';
  150.   DefaultCondensedCols = '132';
  151.   DefaultPrinterCondensedOnCode = #15;
  152.   DefaultPrinterCondensedOffCode = #18;
  153.   DefaultPrinterUnderlineOnCode = Chr(27)+Chr(45)+Chr(49);
  154.   DefaultPrinterUnderlineOffCode = Chr(27)+Chr(45)+Chr(48);
  155.   DefaultPrinterBoldOnCode = Chr(27)+Chr(69);
  156.   DefaultPrinterBoldOffCode = Chr(27)+Chr(70);
  157.  
  158. const
  159.   ScreenCols = 77;
  160.   { Max number of columns that can be used to display the spreadsheet.
  161.     All the 80 columns of the screen cannot be used since the
  162.     spreadsheet is displayed within a window }
  163.  
  164.   ScreenRows = 46;
  165.   { Max numbers of rows that can be used to display the spreadsheet.
  166.     All the 50 rows of a 43/50 lines display cannot be used since the
  167.     spreadsheet is displayed within a window }
  168.  
  169. type
  170.   ScreenColRange = 0..ScreenCols;
  171.   ScreenRowRange = 0..ScreenRows;
  172.  
  173.   ScreenPos = record
  174.   { Stores the position of a point in the screen }
  175.     Col : ScreenColRange;
  176.     Row : ScreenRowRange;
  177.   end; {...ScreenPos }
  178.  
  179.   PScreenArea = ^TScreenArea;
  180.   TScreenArea = object(TObject)
  181.   { Stores the position of an area in the screen and the value of the
  182.     attribute that should be used to display the the text in the area }
  183.        UpperLeft,
  184.        LowerRight : ScreenPos;
  185.        Attrib     : Byte;
  186.     constructor Init(InitX1 : ScreenColRange; InitY1 : ScreenRowRange;
  187.       InitX2 : ScreenColRange; InitY2 : ScreenRowRange; InitAttrib : Word);
  188.     function PointInArea(X, Y: Byte): Boolean;
  189.   end; {...TScreenArea }
  190.  
  191.  
  192. procedure RegisterGLSupprt;
  193. { Register the unit's objects }
  194.  
  195. const
  196.   RBlock : TStreamRec = (
  197.      ObjType : stRBlock;
  198.      VmtLink : Ofs(TypeOf(TBlock)^);
  199.      Load    : @TBlock.Load;
  200.      Store   : @TBlock.Store
  201.   );
  202.  
  203. {****************************************************************************}
  204.                                implementation
  205. {****************************************************************************}
  206.  
  207. uses App;
  208.  
  209. {****************************************************************************}
  210. {**                        Unit's Register procedures                      **}
  211. {****************************************************************************}
  212.  
  213. procedure RegisterGLSupprt;
  214. begin
  215.   RegisterType(RBlock);
  216. end; {...RegisterGLSupprt }
  217.  
  218. {****************************************************************************}
  219. {**                             TBlock Object                              **}
  220. {****************************************************************************}
  221.  
  222. constructor TBlock.Init(InitStart : CellPos);
  223. { Initializes a the starting and ending position of a block of cells }
  224. begin
  225.   Anchor := InitStart;
  226.   Start := Anchor;
  227.   Stop := Anchor;
  228.   AnchorColShifted := False;
  229.   AnchorRowShifted := False;
  230. end; {...TBlock.Init }
  231.  
  232. function TBlock.CellInBlock(CheckCell : CellPos) : Boolean;
  233. { Checks to see if a cell is inside a particular block }
  234. begin
  235.   CellInBlock := (CheckCell.Col >= Start.Col) and
  236.     (CheckCell.Col <= Stop.Col) and (CheckCell.Row >= Start.Row) and
  237.     (CheckCell.Row <= Stop.Row);
  238. end; {...TBlock.CellInBlock }
  239.  
  240. function TBlock.ExtendTo(NewLoc : CellPos) : Boolean;
  241. { Extends a block to the given position }
  242. begin
  243.   ExtendTo := True;
  244.   if (NewLoc.Col >= Anchor.Col) and (NewLoc.Row >= Anchor.Row) then
  245.     begin
  246.       Stop := NewLoc;
  247.       if AnchorColShifted or AnchorRowShifted then
  248.       begin
  249.         Start := Anchor;
  250.         AnchorColShifted := False;
  251.         AnchorRowShifted := False;
  252.       end; {...if AnchorColShifted or AnchorRowShifted }
  253.     end {...if (NewLoc.Col >= Anchor.Col) and (NewLoc.Row >= Anchor.Row) }
  254.   else
  255.     begin
  256.       if NewLoc.Row < Anchor.Row then
  257.         begin
  258.           if not AnchorRowShifted then
  259.             begin
  260.               Start.Row := NewLoc.Row;
  261.               Stop.Row := Anchor.Row;
  262.               AnchorRowShifted := True;
  263.             end {...if not AnchorRowShifted }
  264.           else
  265.             Start.Row := NewLoc.Row;
  266.         end {...if NewLoc.Row < Anchor.Row }
  267.       else
  268.         begin
  269.           if AnchorRowShifted then
  270.           begin
  271.             Start.Row := Anchor.Row;
  272.             AnchorRowShifted := False;
  273.           end; {...if AnchorRowShifted }
  274.           Stop.Row := NewLoc.Row;
  275.         end; {...if/else }
  276.       if NewLoc.Col < Anchor.Col then
  277.         begin
  278.           if not AnchorColShifted then
  279.             begin
  280.               Start.Col := NewLoc.Col;
  281.               Stop.Col := Anchor.Col;
  282.               AnchorColShifted := True;
  283.             end {...if not AnchorColShifted }
  284.           else
  285.             Start.Col := NewLoc.Col;
  286.         end {...if NewLoc.Col < Anchor.Col }
  287.       else
  288.         begin
  289.           if AnchorColShifted then
  290.           begin
  291.             Start.Col := Anchor.Col;
  292.             AnchorColShifted := False;
  293.           end; {...if AnchorColShifted }
  294.           Stop.Col := NewLoc.Col;
  295.         end; {...if/else }
  296.     end; {...if/else }
  297. end; {...TBlock.ExtendTo }
  298.  
  299. constructor TBlock.Load(var S: TStream);
  300. begin
  301.   S.Read(Start, SizeOf(Start));
  302.   Init(Start);
  303.   S.Read(Stop, SizeOf(Stop));
  304. end; {...TBlock.Load }
  305.  
  306. procedure TBlock.Store(var S: TStream);
  307. begin
  308.   S.Write(Start, SizeOf(Start));
  309.   S.Write(Stop, SizeOf(Stop));
  310. end; {...TBlock.Store }
  311.  
  312.  
  313. {****************************************************************************}
  314. {**                          TScreenArea Object                            **}
  315. {****************************************************************************}
  316.  
  317. constructor TScreenArea.Init (InitX1: ScreenColRange; InitY1: ScreenRowRange;
  318.   InitX2: ScreenColRange; InitY2: ScreenRowRange; InitAttrib: Word);
  319. begin
  320.   UpperLeft.Col := InitX1;
  321.   UpperLeft.Row := InitY1;
  322.   LowerRight.Col := InitX2;
  323.   LowerRight.Row := InitY2;
  324.   Attrib := InitAttrib;
  325. end; {...TScreenArea.Init }
  326.  
  327. function TScreenArea.PointInArea(X, Y: Byte): Boolean;
  328. { Determines if the given point is in the area defined by the object }
  329. begin
  330.   if (X >= UpperLeft.Col) and (X <= LowerRight.Col) and (Y >= UpperLeft.Row)
  331.      and (Y <= LowerRight.Row) then
  332.     PointInArea := True
  333.   else
  334.     PointInArea := False;
  335. end; {...TScreenArea.PointInArea }
  336.  
  337. end. {...GLSupprt unit }